package com.example.day2003;

/**
 * @author Lenovo
 */
public class SellTicket {
    private static int tickets = 100;
    private int x = 0;


    public void run() {
        while (true) {
            sellTicket();
        }
    }

    private static synchronized void sellTicket() {
        if (tickets > 0) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "正在出售第" +
                    tickets + "张票");
            tickets--;
        }
    }
}
